package com.yycx.module.bus.provider.handler.haiying.custombalance;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.constants.CommonConstants;
import com.yycx.common.mybatis.interceptor.PageInterceptor;
import com.yycx.common.mybatis.model.PageParams;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.security.OpenHelper;
import com.yycx.common.security.OpenUser;
import com.yycx.module.admin.client.entity.BaseUser;
import com.yycx.module.bus.client.entity.BusCustom;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.client.enums.AmountTypeEnum;
import com.yycx.module.bus.provider.service.BusCustomService;
import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 预付款收款收款单
 *
 * @author zyf
 */
@Component
public class HyYfkSelectListHandler implements PageInterceptor<BusPayment> {


    @Autowired
    private BusCustomService customService;

    @Override
    public void prepare(CriteriaQuery<BusPayment> cq, PageParams pageParams, EntityMap params) {
        String customCode = params.get("customCode");
        Long companyId = OpenHelper.getCompanyId();
        BusCustom custom = customService.selectByCustomCode(customCode, companyId);
        if (FlymeUtils.isEmpty(custom)) {
            custom = new BusCustom();
        }
        cq.select(BusPayment.class, "*");
        cq.addSelect(BusCustom.class, "customName");
        //cq.isNull("payment.orderId");
        cq.gt("payment.surplusAmount", 0);
        cq.eq(true, "amountType", AmountTypeEnum.YfkAmount.getCode());
        cq.eq(true, "payment.companyId", companyId);
        cq.eq(true, "payment.customId", custom.getCustomId());
        cq.eq(true, "payment.paymentState", CommonConstants.INT_2);
        cq.createJoin(BusCustom.class);
        cq.orderByDesc("payment.createTime");
    }


}
